#! /bin/bash

set -e
psql -v ON_ERROR_STOP=1 --username="$POSTGRES_USER" <<-EOSQL
\c notes_db;
create table if not exists note_profiles (
  id INTEGER primary key not null, 
  title varchar(300) not null,
  deleted BOOLEAN not null default FALSE
);

create table if not exists notes (
  id SERIAL not null, 
  version INTEGER not null,
  content text not null, 
  created_date DATE DEFAULT CURRENT_DATE,
  modified_date DATE null,
  primary key (id, version)
);

create table if not exists user_notes (
  user_id varchar(80) not null, 
  note_id INTEGER not null,
  primary key (user_id, note_id)
);

END;
EOSQL
